<script>
	import Vue from "vue"
	export default {
		onLaunch: function() {
			console.warn('当前组件仅支持 uni_modules 目录结构 ，请升级 HBuilderX 到 3.1.0 版本以上！')
			console.log('App Launch');
			
			//全局页面进出过渡，仅H5使用
			// #ifdef H5
			this.pageShow();
			this.$router.beforeEach((to, from, next) => {
				this.pageHide(next)
			})
			this.$router.afterEach(() => {
				setTimeout(this.pageShow, 50)
			})
			// #endif
			
			//每5分钟刷新一次认证,提前30秒
			// setInterval(() => {
			// 	this.$http.nquest({
			// 		url: "refreshToken",
			// 		data: {
			// 			isDebug: true
			// 		},
			// 		noErrMsg:true,
			// 		noLoading:true
			// 	});
			// }, (this.$http.appTimeout - 30000));
			
			//获取系统信息
			//写入$sysInfo，屏幕尺寸
			//写入$sysLang，语言包。为了能在页面创建前调用而写在main.js，否则须在页面created周期后重新赋值
			const sysInfo = {};
			Vue.prototype.$sysInfo = sysInfo;
			try {
			    const systemInfo = uni.getSystemInfoSync();
				sysInfo["pageSize"] = this.checkPageSize(systemInfo.windowWidth);
				sysInfo["topfix"] = uni.upx2px(90)+systemInfo.statusBarHeight +"px";
				Vue.prototype.$sysLang = systemInfo.language;
				console.log("获取系统信息成功",Vue.prototype.$sysInfo, Vue.prototype.$sysLang);
			} catch (e) {
			    sysInfo["pageSize"] = "md";
				Vue.prototype.$sysLang = "zh-CN";
				console.log("获取系统信息失败",e,Vue.prototype.$sysInfo, Vue.prototype.$sysLang);
			}
			//监听窗口重置
			uni.onWindowResize((res) => {
				sysInfo["pageSize"] = this.checkPageSize(res.size.windowWidth);
			});
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			// #ifdef H5
			pageHide(callback) {
				const classList = document.querySelector('uni-page').classList
				classList.add('animation-before', 'animation-leave')
				classList.remove('animation-show')
				setTimeout(() => {
					classList.remove('animation-before', 'animation-leave')
					callback && callback()
				}, 300)
			},
			pageShow() {
				const classList = document.querySelector('uni-page').classList
				classList.add('animation-before')
				setTimeout(() => {
					classList.add('animation-enter', 'animation-after', 'animation-show')
					setTimeout(() => {
						classList.remove('animation-before', 'animation-after', 'animation-enter')
					}, 300)
				}, 20)
			},
			// #endif
			
			checkPageSize(w){
				if(!w){
					return "md"
				}
				if(w<375){
					return "xs"
				}else if(w<415){
					return "sm"
				}else if(w<800){
					return "md"
				}else{
					return "lg"
				}
			},
		}
	}
</script>

<style>
	@import url("./static/css/font.css");
</style>

<style lang="scss">
@import "/static/css/vicode.scss";
@import "/static/css/main.scss";
@import "/static/css/page.scss";
@import "/static/css/icon.scss";
</style>